Skip to content

feat(client): add SUNIONCARD and SDIFFCARD set cardinality commands#3336

Open
nkaradzhov wants to merge 2 commits into
redis:masterfrom
nkaradzhov:set-commands
Open

feat(client): add SUNIONCARD and SDIFFCARD set cardinality commands#3336
nkaradzhov wants to merge 2 commits into
redis:masterfrom
nkaradzhov:set-commands

Conversation

@nkaradzhov

@nkaradzhov nkaradzhov commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

This pull request adds support for the Redis 8.10 set cardinality commands SUNIONCARD and SDIFFCARD.

Both commands compute the cardinality of a derived set operation in a single read-only command without materializing or returning the derived set:

  • SUNIONCARD numkeys key [key ...] [APPROX] [LIMIT limit] — distinct-element count of the union of the given sets. Supports exact mode (default), optional APPROX (HyperLogLog estimate), and optional LIMIT cap (LIMIT 0 = no limit). Options emitted in canonical order APPROX before LIMIT.
  • SDIFFCARD numkeys key [key ...] [LIMIT limit] — element count of the difference between the first set and all successive sets. Exact mode with optional LIMIT. APPROX is intentionally not exposed (out of scope until server semantics are defined; the server rejects it with a syntax error).

Both use pushKeysLength for the numkeys-prefixed key list, are flagged IS_READ_ONLY, and return a NumberReply. Server errors propagate unchanged; no client-side validation is added. Registered under raw (SUNIONCARD/SDIFFCARD) and camelCase (sUnionCard/sDiffCard) names.

Behavior considerations: exact LIMIT returns min(realCardinality, limit); APPROX results are approximate integers not exceeding limit. No backward-compatibility risk — new commands only.

🤖 Generated with Claude Code


Note

Low Risk
Additive read-only command definitions mirroring SINTERCARD; no changes to existing behavior.

Overview
Adds Redis 8.10 client support for SUNIONCARD and SDIFFCARD, read-only commands that return set union or set-difference cardinality without materializing members.

Each command is implemented with pushKeysLength, IS_READ_ONLY, and a NumberReply. SUNIONCARD accepts optional APPROX (HyperLogLog) and LIMIT (emitted as APPROX then LIMIT). SDIFFCARD only exposes LIMIT; APPROX is not wired on the client. Both are registered in the command index as raw and camelCase (sUnionCard / sDiffCard). Specs cover argument encoding and integration tests gated on Redis ≥ 8.10.

Reviewed by Cursor Bugbot for commit 105ce3f. Bugbot is set up for automated code reviews on this repo. Configure here.

nkaradzhov and others added 2 commits July 13, 2026 14:00
Add read-only cardinality commands for derived set operations.

SUNIONCARD numkeys key [key ...] [APPROX] [LIMIT limit] returns the
distinct-element count of the union; supports exact mode (default),
optional APPROX (HyperLogLog), and optional LIMIT (LIMIT 0 = no limit),
emitted in canonical order APPROX before LIMIT.

SDIFFCARD numkeys key [key ...] [LIMIT limit] returns the element count
of the difference between the first set and all successive sets. APPROX
is not exposed (out of scope until server semantics are defined).

Both use pushKeysLength for the numkeys-prefixed key list, are flagged
IS_READ_ONLY, return a NumberReply, and propagate server errors as-is.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Add isVersionGreaterThanHook([8, 10]) so integration tests skip on
  pre-8.10 servers instead of failing with unknown-command errors.
- Add @see links and "Added since Redis 8.10." to the registry entries,
  matching the surrounding set-command convention.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nkaradzhov nkaradzhov requested a review from PavelPashov July 13, 2026 11:52
@nkaradzhov nkaradzhov marked this pull request as ready for review July 13, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant